package com.xingda.packing.led.impl;

import com.xingda.packing.led.LedConnService;
import com.xingda.packing.led.LedHelper;
import com.xingda.packing.led.LedOperateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.net.Socket;
import java.util.Objects;

@Slf4j
@Component
public class LedOperateServiceImpl implements LedOperateService {

    @Resource
    LedConnService ledConnService;

    @Override
    public void write(String content, String ip, int port) {
        Socket socket = ledConnService.getConn(ip, port);
        if (Objects.isNull(socket)) {
            log.debug("socket 为空，ip-{} ,port-{}", ip, port);
            return;
        }
        LedHelper.send(content, socket);
    }

    @Override
    public void write(String content, String ip, int port, String color) {
        Socket socket = ledConnService.getConn(ip, port);
        if (Objects.isNull(socket)) {
            log.debug("socket 为空，ip-{} ,port-{}", ip, port);
            return;
        }
        LedHelper.send(content, socket, color);
    }
}
